#pragma once

#include "Color.h"


namespace uml {

const int Color::red_default_ = 0;
const int Color::green_default_ = 0;
const int Color::blue_default_ = 0;
void Color::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    red_ = json.value("red").toInt(red_default_);
    green_ = json.value("green").toInt(green_default_);
    blue_ = json.value("blue").toInt(blue_default_);
}

void Color::toJson(QJsonObject& json) {
    if (red_ != red_default_) {
        json.insert("red", red_);
    }
    if (green_ != green_default_) {
        json.insert("green", green_);
    }
    if (blue_ != blue_default_) {
        json.insert("blue", blue_);
    }
}

/// <summary>
/// red getter
/// the red component of the color in the range (0..255).
/// </summary>
int Color::red() const {
    return red_;
}

/// <summary>
/// red setter
/// the red component of the color in the range (0..255).
/// </summary>
void Color::setRed(int value) {
    red_ = value;
}

/// <summary>
/// green getter
/// the red component of the color in the range (0..255).
/// </summary>
int Color::green() const {
    return green_;
}

/// <summary>
/// green setter
/// the red component of the color in the range (0..255).
/// </summary>
void Color::setGreen(int value) {
    green_ = value;
}

/// <summary>
/// blue getter
/// the red component of the color in the range (0..255).
/// </summary>
int Color::blue() const {
    return blue_;
}

/// <summary>
/// blue setter
/// the red component of the color in the range (0..255).
/// </summary>
void Color::setBlue(int value) {
    blue_ = value;
}

} // namespace uml
